/**
map键值对
 *WangGANG
 *2018/7/18
 */
package main

import "fmt"

func main()  {
	//初始化map
	mapName := map[string]string{"a":"apple","b":"blue"}
	//添加map
	mapName["c"] = "class"
	fmt.Println(mapName)

	for country,_ := range mapName{
		//通过map的键取相应的值
		fmt.Printf("键:%s,值:%s\n",country,mapName[country])
	}

	for country,kk := range mapName{
		//直接通过for循环取键值对
		fmt.Println(country,kk)
	}

	/*查看元素在集合中是否存在 */
	//country获取相应的map的值，ok获取的是状态位(true|false)
	country,ok := mapName["a1"]
	if (ok) {
		fmt.Println("美国的首都是", country,ok)
	} else {
		fmt.Println("美国的首都不存在",ok)
	}

	//删除元素,通过键删除
	delete(mapName,"b")
	fmt.Printf("删除元素:%s\n",mapName)

}
